var echarts;
var zul;
$(document).ready(function () {
    require.config({
        baseUrl: ctx + '/resource/plugins/echarts4',
        paths: {
            echarts: 'echarts',
            roma: 'theme/roma',
        }
    });
    require(
        [
            'echarts',
            'roma'
        ],
        function (ec) {
            ECharts = ec;
            querySjtbInfo();//数据同步基本信息

            querySjtbYbp();//数据同步可用性

            qyeryJkdYbp();//数据同步健康度

        }
    );
});

/**数据同步基本信息*/
function querySjtbInfo() {
    $.ajax({
        url: ctx + "/HostPage/queryTableInfo",
        type: "post",
        data: {CI_TYPE: CI_TYPE},
        success: function (data) {
            var map = JSON.parse(data);
            var list = map.list;
            var list1 = map.list1;
            var tablel = "";
            zul = list1[0].ZSL;
            tablel += "<ul>" +
                "<li class='first' style='width:25%'>" + "分类" + "</li>" +
                " <li style='width:25%'>" + "资源总数" + "</li>" +
                "<li style='width:25%'>" + list[0].BIZ_TYPE + "</li>" +
                "<li class='last' style='width:25%'>" + list[1].BIZ_TYPE + "</li>" +
                "</ul>" +
                "<ul>" +
                "<li class='first' style='width:25%'>" + "数量" + "</li>" +
                " <li style='width:25%'>" + list1[0].ZSL + "台" + "</li>" +
                "<li style='width:25%'>" + list[0].SL + "台" + "</li>" +
                "<li class='last' style='width:25%'>" + list[1].SL + "台" + "</li>" +
                "</ul>";
            $("#host_info").append(tablel);
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });
}

/**数据同步可用性*/
function querySjtbYbp() {
    $.ajax({
        url: ctx + "/HostPage/queryYbp",
        type: "post",
        data: {KPI_CODE: "FM-10-32-001-01"},
        success: function (data) {
            var cpuState = JSON.parse(data);
            var qq = "<div class='easy-pie-chart percentage' data-percent='' id='sjtb_kyx' data-color='#5eadf0'style='height: 75px; width: 75px; line-height: 74px; color: rgb(135, 184, 127);'>" +
                "<span class='percent' style='top:0px;left:40px;'>" + parseInt(cpuState[0].SUCCESS_VALUE / cpuState[0].COUNT_VALUE * 100) + "%" + "</span>" +
                "<canvas height='75' width='75'>" + "</canvas>" + "</div>" + "<h3 style='line-height:3;'>" + "可用性" + "</h3>";
            $("#sjtb_sjtb").append(qq);
            $('#sjtb_kyx').attr('data-percent', parseInt(cpuState[0].SUCCESS_VALUE / cpuState[0].COUNT_VALUE * 100));

            $('.easy-pie-chart.percentage').each(function () {
                $(this).easyPieChart({
                    barColor: $(this).data('color'),
                    trackColor: '#EEEEEE',
                    scaleColor: false,
                    lineCap: 'butt',
                    lineWidth: 8,
                    animate: ace.vars['old_ie'] ? false : 1000,
                    size: 120
                }).css('color', $(this).data('color'));
            });
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });

}

//数据同步健康度
function qyeryJkdYbp() {
    $.ajax({
        url: ctx + "/HostPage/queryJkd",
        type: "post",
        data: {CI_TYPE: CI_TYPE},
        success: function (data) {
            var cpuState = JSON.parse(data);
            var qq = "<div class='easy-pie-chart percentage' data-percent='' id='sjtbjkd' data-color='#87B87F'style='height: 75px; width: 75px; line-height: 74px; color: rgb(135, 184, 127);'>" +
                "<span class='percent' style='top:0px;left:40px;'>" + parseInt((zul - cpuState[0].EXT_UNIT_ID) / zul * 100) + "%" + "</span>" +
                "<canvas height='75' width='75'>" + "</canvas>" + "</div>" + "<h3 style='line-height:3;'>" + "健康度" + "</h3>";
            $("#sjtb_jkd").append(qq);
            $('#sjtbjkd').attr('data-percent', parseInt((zul - cpuState[0].EXT_UNIT_ID) / zul * 100));

            $('.easy-pie-chart.percentage').each(function () {
                $(this).easyPieChart({
                    barColor: $(this).data('color'),
                    trackColor: '#EEEEEE',
                    scaleColor: false,
                    lineCap: 'butt',
                    lineWidth: 8,
                    animate: ace.vars['old_ie'] ? false : 1000,
                    size: 120
                }).css('color', $(this).data('color'));
            });
        }, error: function (textStatus) {
            console.log("error:" + textStatus.status);
        }
    });

}
